package com.ruifu.conversions.utils;

import com.github.tobato.fastdfs.proto.storage.DownloadByteArray;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class FastDFSClient {
    @Autowired
    private FastFileStorageClient storageClient;

    /**
     * 获取文件byte[]
     *
     * @param fileUrl
     * @throws Exception
     */
    public byte[] copyFile(String fileUrl) throws Exception {
        // 根据文件标识从文件服务器获取文件数组
        String group = fileUrl.substring(0, fileUrl.indexOf("/"));
        String path = fileUrl.substring(fileUrl.indexOf("/") + 1);
        DownloadByteArray downloadByteArray = new DownloadByteArray();
        return storageClient.downloadFile(group, path, downloadByteArray);
    }
}
